package lxm.demo.ultra;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;


public class PtrFrameFragment extends Fragment {


    Unbinder unBinder;
    @BindView(R2.id.frag_ptr_cls_frame_layout)
    PtrClassicFrameLayout ptrClsFrameLayout;

    public static PtrFrameFragment getInstance() {
        PtrFrameFragment ptrFrameFragment = new PtrFrameFragment();
        return ptrFrameFragment;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_ptr_frame, container, false);
        unBinder = ButterKnife.bind(this, inflate);
        ptrClsFrameLayout.setLastUpdateTimeRelateObject(this);
        ptrClsFrameLayout.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                frame.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptrClsFrameLayout.refreshComplete();
                    }
                }, 1000);
            }

            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return true;
            }
        });
        return inflate;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unBinder.unbind();
    }
}

